/*
 * Copyright and license
 */
package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
 * This is the frame for the information about the software
 * @author JuanK
 *
 */
public class AboutFrame extends JDialog implements ActionListener{

	/**
	 * Serial
	 */
	private static final long serialVersionUID = 1L;
	
	private MainFrame instance;
	
	private JPanel panel;
	
	/**
	 * Buttons and labels
	 */
	private JButton buttonClose;
	private JLabel labelIcon;
	private ImageIcon icon;
	
	/**
	 * Action Commands
	 */
	private static String ACTION_CLOSE = "ACTION_CLOSE";
	
	public AboutFrame(MainFrame mf)
	{
		instance = mf;
		init();
	}
	private void init()
	{
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.setSize(300, 300);
		this.setLocation(screenSize.width/2 - 150, screenSize.height/2 - 150);
		this.setUndecorated(true);
		this.setResizable(false);
		this.setAlwaysOnTop(true);
		
		panel = new JPanel();
		panel.setBorder(BorderFactory.createLineBorder(Color.black));
		panel.setLayout(new BorderLayout());
		
		buttonClose = new JButton("Close");
		buttonClose.addActionListener(this);
		buttonClose.setActionCommand(ACTION_CLOSE);
		
		icon = new ImageIcon("./ext/images/logo.png");
		labelIcon = new JLabel("Developed by: DuqueSoft & IbaSoft", icon, JLabel.CENTER);
		labelIcon.setVerticalTextPosition(JLabel.BOTTOM);
		labelIcon.setHorizontalTextPosition(JLabel.CENTER);
		panel.add(labelIcon, BorderLayout.CENTER);
		panel.add(buttonClose, BorderLayout.SOUTH);
		this.add(panel);
	}
	@Override
	public void actionPerformed(ActionEvent event) {
		String actionCommand = event.getActionCommand();
		if(actionCommand.equals(ACTION_CLOSE))
		{
			this.setAlwaysOnTop(false);
			instance.setEnabled(true);
			this.dispose();
		}
		
	}
}
